package abstracttransactions

import (
	"fmt"
	"log"
	"salary/database"
	"salary/model"
	"strconv"
)

/*
 * 更改雇员属性
 * 实现抽象类
 */

type IChange interface {
	Change(employee *model.Employee)
}

type ChangeEmployeeTransaction struct {
	empid int
	IChange
}

func NewChangeEmployeeTransaction(empid int) ChangeEmployeeTransaction {
	return ChangeEmployeeTransaction{empid: empid}
}

func (cet *ChangeEmployeeTransaction) SetEmpid(empid int) {
	cet.empid = empid
}

func (cet *ChangeEmployeeTransaction) Execute() {
	e := database.Database.GetEmployee(cet.empid)
	if &e == nil {
		err := fmt.Errorf(database.ExceptionMessage.EmployeeNotExist + strconv.Itoa(cet.empid))
		log.Println(err.Error())
		return
	}
	cet.Change(e)
}


